//index.js
//所有商品
const app = getApp()

Page({
  http: require('../../utils/http.js'),
  globalVariable: require('../../utils/globalVariable.js'),
  data: {
    shop: '',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    goods: [],
  },
  //事件处理函数
  bindViewTap: function() {
    var that = this;
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  requestTest: function() {
    var that = this;
    wx.request({
      url: "http://127.0.0.1:9100/test",
      success: res => {
        that.setData({
          motto: res.data
        })
      },
      fail: res => {
        that.setData({
          motto: "错误"
        })
      }
    })
  },
  onLoad: function () {
    this.http.getAllGoods(
      res => {
        this.globalVariable.saveGoods(res.data.data)
        this.setData({
          goods: res.data.data
        })
      }
    )
  },
  toDetailsTap: function(e){
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: "/pages/goods-detail/index?id=" + e.currentTarget.dataset.id,
    })
  }
})
